import {Component} from '@angular/core';
import {IonicPage, NavController, NavParams} from 'ionic-angular';
import {SideMenuService} from "../../../services/common/side-menu.service";
import {ClientRenwalDetailProvider} from "../../../providers/client/client-renwal-detail/client-renwal-detail.provider";
import * as moment from 'moment';
import {LoadingService} from "../../../services/common/loading.service";
/**
 * 续期详情
 */

@IonicPage()
@Component({
    selector: 'page-client-renwal-detail',
    templateUrl: 'client-renwal-detail.html',
    providers: [
        SideMenuService,
        ClientRenwalDetailProvider
    ]
})
export class ClientRenwalDetailPage {
    public dataModel;
    isLoaded :boolean = false;
    public data =
        [
            {
                'policyID': '12123154125', //保单号
                'mainRisk': '理财通分红终身计划',
                'policyHolder': '爱中宏',
                'agePolicyHolder': '50',
                'sexPolicyHolder': 'M',
                'recognizee': '小红',//被保人
                'ageRecognizee': '45',
                'sexRecognizee': 'F',
                'policyValueDate': '2018/08/05',//生效日
                'payment': '2018/03/05' //下期应交保费日
            },
            {
                'policyID': '12123154125', //保单号
                'mainRisk': '理财通分红终身计划',
                'policyHolder': '爱中宏',
                'agePolicyHolder': '50',
                'sexPolicyHolder': 'M',
                'recognizee': '小红',//被保人
                'ageRecognizee': '45',
                'sexRecognizee': 'F',
                'policyValueDate': '2018/08/05',//生效日
                'payment': '2018/03/05' //下期应交保费日
            },
            {
                'policyID': '12123154125', //保单号
                'mainRisk': '理财通分红终身计划',
                'policyHolder': '爱中宏',
                'agePolicyHolder': '50',
                'sexPolicyHolder': 'M',
                'recognizee': '小红',//被保人
                'ageRecognizee': '45',
                'sexRecognizee': 'F',
                'policyValueDate': '2018/08/05',//生效日
                'payment': '2018/03/05' //下期应交保费日
            },

        ];


    constructor(public navCtrl: NavController,
                public navParams: NavParams,
                private sideMenuService: SideMenuService,
                private renwalDetail: ClientRenwalDetailProvider,
                private load: LoadingService,
                ) {
    }

    ionViewDidLoad() {
        this.getRenenwalDetail(this.navParams.get("id"),this.navParams.get('days'))
    }

    /**
     * 返回
     * @param ev
     */
    backButtonClick(ev) {
        ev.preventDefault();
        ev.stopPropagation();
        this.navCtrl && this.navCtrl.pop(null, null);
    }

    /**
     * 时间转换
     */
    momentTime(date){
        return moment(date).format('YYYY/MM/DD');
    }
    /**
     * 跳转到保单详情
     */
    // goToPolicysDetail(id){
    //     this.navCtrl.push("PolicyDetailPage",{"policyNO":id})
    // }
    goToPolicysDetail(policyNO: string, policyPayToDate: string,policyStatus: string,policyStatusCode: string, orphanType: string, agentCode: string){
        this.navCtrl.push('PolicyDetailsPage', {
            policyNO: policyNO,
            policyPayToDate: policyPayToDate,
            policyStatus: policyStatus,
            policyStatusCode: policyStatusCode,
            orphanType: orphanType,
            agentCode: agentCode?agentCode:''
        });
    }

    /**
     * 跳转到投保人详情
     */
    goToHolderDetail(id){
        this.navCtrl.push("HolderClientDetailPage",{"clientNum":id})
    }

    /**
     * 跳转到被保人详情
     */
    goToInsuredDetail(id){
        this.navCtrl.push("HolderClientDetailPage",{"clientNum":id})
    }

    /**
     * 打开菜单栏
     * @param myEvent
     */
    openMenu(myEvent) {
        this.sideMenuService.openSideMenu(myEvent)
    }

    isShowTotal=true;
    /**
     * 获取续期详情
     */
    getRenenwalDetail(id,days) {
        this.isShowTotal =false;
        this.isLoaded = false;
        this.load.showLoading();
        this.renwalDetail.getRenewalDetail(0, id,days).subscribe((res) => {
            this.dataModel = res;
            this.isLoaded = true;
            this.isShowTotal =true;
            this.load.dismissLoading();
        }, () => {
            this.isShowTotal =true;
            this.load.dismissLoading();
        })
    }
}
